<!--单选，多选选择列表组件，实例-->
<template>
  <div class="page">
    <div  class="edit-pop"   v-if='isShow'  >
    <el-dialog class='select-house' :visible.sync="isShow"
      :title="title" :close-on-click-modal="false" @close="onClose" width="1000px" style="border-radius: 10px">

      <div class="edit-pop-content">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
          <el-form-item label="中心名称" prop="centerName">
            <el-input v-model="queryParams.centerName" placeholder="请输入中心名称" clearable size="small" @keyup.enter.native="handleQuery"/>
          </el-form-item>
         <el-form-item label="机构名称" prop="orgName">
            <el-input v-model="queryParams.orgName" placeholder="请输入机构名称" clearable size="small" @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>


        <el-table height="calc(100vh - 400px)" v-loading="loading" :data="prodList" @selection-change="handleSelectionChange"
                  highlight-current-row
                  @current-change="handleCurrentChange"
                  @on-load="getList">
          <el-table-column  v-if="multiple" type="selection" width="55" align="center" />
          <el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" />
          <el-table-column label="中心名称"  align="center" prop="centerName" />
          <el-table-column label="所属机构" align="center" prop="orgName" width="150"/>
          <el-table-column label="省" align="center" prop="centerProvince" width="100" />
          <el-table-column label="市" align="center" prop="centerCity" width="100"  />
          <el-table-column label="地址" align="center" prop="centerAddress" />
          <el-table-column  v-if="!multiple" label="操作" align="center" width="160" class-name="small-padding fixed-width">
            <template  slot-scope="scope">
              <el-button size="mini" icon="el-icon-circle-check" type="text" @click="handleCurrentChange(scope.row)">选择</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      </div>
      <template #footer  v-if="multiple">
        <div class="dialog-footer">
          <el-button @click="onClose">取消</el-button>
          <el-button type="primary" @click="confirm">确认</el-button>
        </div>
      </template>
    </el-dialog>
  </div>  </div>
</template>
<script>
//改成项目中用到的接口
// import {  listCenters, }   from "@/api/yyd/centers";

export default {
  props: {
    // 是否多选
    multiple: {
      type: Boolean,
      default: false,
    },
    // 弹框标题
    title: {
      type: String,
      default: '选择中心',
    },
    // 子公司编码
    companyCode: {
      type: String,
      default:'',
    },
    // 仓库分类编码 1成品仓库 2备件仓库 3共享仓库
    warehouseClassCode: {
      type: String,
      default:'',
    },
  },
  data() {
    return {
      showMoreCondition: false,//是否展开搜索条件
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      tMultiple: true,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgName: undefined,
        centerName: undefined,
      },
      prodList:[],
      // 总条数
      total: 0,
      isShow: true,
      loading: false,
      selectionList:[],//选中的数据
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      //改成项目中用到的接口
      // listCenters(this.queryParams).then(response => {
      //   this.prodList = response.rows;
      //   this.total = response.total;
      //   this.loading = false;
      // });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log("多选框选中数据selection:",selection)
      this.ids = selection.map(item => item.centerId)
      this.selectionList=selection||[];
      this.single = selection.length!==1
      this.tMultiple = !selection.length
    },


    //点击行
    handleCurrentChange(val) {
      console.log("单击",val)
      console.log("单击this.multiple",this.multiple)
      this.selectionList.push(val);
      if (!this.multiple) {
        this.$emit('confirm', [val]);
        this.onClose();
      }
    },
    //确定
    confirm() {
      console.log("selectionList",this.selectionList);
      let data=this.selectionList;
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少勾选一条数据');
        return;
      }
      this.$emit('confirm', data.length ? data : [{}]);
      this.onClose();
    },
    onClose() {
      this.isShow = false;
      this.$emit('close', false);
    },
  },
};
</script>
<style lang="scss" scoped>
.page {
  :deep(.el-dialog__body) {
    padding: 20px 20px 0 !important;
  }
}
</style>
